import React, { Component } from 'react';
import { Form, Row, Col } from 'antd';
import ShowType from '../../../routes/common/showType';
import styles from '../../../index.less';

const FormItem = Form.Item;

class TabSysParamComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      sTabId: props.app.currentPane.key, /* 当前标签 */
      componentName: props.componentName, /* 组件名 */
      masterConfig: props.masterConfig, /* 配置 */
      sId: props.sId, /* 业务数据Id */
      dataList: [], /* 数据 */
      sActiveId: props.sActiveId, /* 窗体Id */
      disabled: props.disabled, /* 是否是查看状态 */
      sCbxMaterialsUnit: '', /* 材料单位 */
      sCbxCardboardUnit: '', /* 纸箱单位 */
      sCbxMachineUnit: '', /* 上机规格计量单位 */
      dNetConversionRate: '', /* 转化率 */
      dNetMoney: '', /* 金额 */
      dNetPrice: '', /* 价格 */
      iNetSquareM: '', /* 平方转米小数位 */
      bCkxPercentile: '', /* 小数位(6) */
      sCbxDateTime: '', /* 显示日期时间格式 */
      sCbxLanguage: '', /* 默认语言 */
      iCbxExitSystem: '', /* 系统不操作退出(分钟) */
      sCbxNetID: '', /* 外网ID */
      sCbxNetVerifyCode: '', /* 接口验证码 */
      sCbxHttp: '', /* 网络地址 */
      iNetMonth: '', /* 数据默认显示月(个) */
      sCbxServerFilePath: '', /* 服务器文件路径 */
      sCbxCompanyName: '', /* 公司名称 */
      sCbxCompanyTitle: '', /* 报表打印标题 */
      sCbxCompanyAddress: '', /* 公司地址 */
      sCbxCompanyInoviceAddress: '', /* 开票地址 */
      sCbxCompanyPhone1: '', /* 电话1 */
      sCbxCompanyPhone2: '', /* 电话2 */
      sCbxCompanyFax: '', /* 传真 */
      sCbxCompanyEmail: '', /* 电子邮件 */
      sCbxHr: '', /* 人事专员 */
      sCbxWorkPath: '', /* 工单合版Json获取路径 */
      sCbxWorkCheckPath: '', /* 工单合版check获取路径 */
      sCbxTime: '', /* 截稿时间点 */
      sCbxImpositionTime: '', /* 拼版时间点 */
    };
  }
  componentWillMount() {
    /* 获取主表数据 */
    const { masterConfig, sId } = this.state;
    if (masterConfig.gdsconfigformslave !== undefined) {
      const mainConfig = masterConfig.gdsconfigformslave;
      this.setState({
        sId: sId !== undefined ? sId : '',
        sCbxMaterialsUnit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxmaterialsunit'))[0],
        sCbxCardboardUnit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcardboardunit'))[0],
        sCbxMachineUnit: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxmachineunit'))[0],
        dNetConversionRate: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'dnetconversionrate'))[0],
        dNetMoney: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'dnetmoney'))[0],
        dNetPrice: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'dnetprice'))[0],
        iNetSquareM: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetsquarem'))[0],
        bCkxPercentile: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'bckxpercentile'))[0],
        sCbxDateTime: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxdatetime'))[0],
        sCbxLanguage: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxlanguage'))[0],
        iCbxExitSystem: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'icbxexitsystem'))[0],
        sCbxNetID: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxnetid'))[0],
        sCbxNetVerifyCode: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxnetverifycode'))[0],
        sCbxHttp: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxhttp'))[0],
        iNetMonth: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'inetmonth'))[0],
        sCbxServerFilePath: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxserverfilepath'))[0],
        sCbxCompanyName: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyname'))[0],
        sCbxCompanyTitle: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanytitle'))[0],
        sCbxCompanyAddress: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyaddress'))[0],
        sCbxCompanyInoviceAddress: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyinoviceaddress'))[0],
        sCbxCompanyPhone1: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyphone1'))[0],
        sCbxCompanyPhone2: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyphone2'))[0],
        sCbxCompanyFax: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyfax'))[0],
        sCbxCompanyEmail: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxcompanyemail'))[0],
        sCbxHr: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxhr'))[0],
        sCbxWorkPath: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxworkpath'))[0],
        sCbxWorkCheckPath: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxworkcheckpath'))[0],
        sCbxTime: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbxtime'))[0],
        sCbxImpositionTime: mainConfig.filter(item => (item.sControlName.toLowerCase() === 'scbximpositiontime'))[0],
      });
    }
  }

  componentWillReceiveProps(nextProps) {
    const {
      sId, disabled, content, dataSet,
    } = nextProps;
    const { dataList } = content;
    const {
      sDataListTabId, returnType, urlData, loading, componentName,
    } = dataList;
    this.setState({ disabled, dataList: dataSet });
    if (this.state.sTabId === sDataListTabId && this.state.sTabId === nextProps.app.currentPane.key
      && this.state.componentName === componentName) {
      if (loading) return;
      if (returnType === 'data') {
        this.setState({
          dataList: urlData,
          sId: sId !== undefined ? sId : '',
        });
      }
    }
  }

  shouldComponentUpdate(nextProps, nextState) {
    const { componentName } = nextProps;
    const { sId } = this.props;
    if (sId === undefined) {
      return true;
    }
    let flag = true;
    if (nextState.disabled !== this.state.disabled) {
      return true;
    }
    if (this.state.sTabId === nextProps.app.currentPane.key &&
      this.state.componentName === componentName) {
      flag = true;
    } else {
      flag = false;
    }
    return flag;
  }

  render() {
    const {
      app, form, handleModalPane, dataName, dataType, handleSelectChange, onClose,
    } = this.props;
    const {
      dataList, sId, sActiveId, disabled,
    } = this.state;
    const childProps = {
      app,
      form,
      sActiveId,
      sId,
      disabled,
      handleModalPane,
      handleSelectChange,
      dataName,
      dataType,
      onClose,
    };
    /* 仅针对于弹窗，如其他需配置弹窗，也必须配置 */
    const sCbxHrDataList = dataList.filter(item => (item.sName === 'sCbxHr'));
    const sCbxHrData = sCbxHrDataList.length > 0
      ? { [sCbxHrDataList[0].sName]: sCbxHrDataList[0].sValue }
      : {};
    const sCbxServerFilePathDataList = dataList.filter(item => (item.sName === 'sCbxServerFilePath'));
    const sCbxServerFilePathData = sCbxServerFilePathDataList.length > 0
      ? { [sCbxServerFilePathDataList[0].sName]: sCbxServerFilePathDataList[0].sValue }
      : {};
    const {
      sCbxMaterialsUnit, sCbxCardboardUnit, sCbxMachineUnit, dNetConversionRate,
    } = this.state;
    const {
      dNetMoney, dNetPrice, iNetSquareM, bCkxPercentile,
    } = this.state;
    const { sCbxDateTime, sCbxLanguage, iCbxExitSystem } = this.state;
    const { sCbxNetID, sCbxNetVerifyCode, sCbxHttp } = this.state;
    const {
      iNetMonth, sCbxServerFilePath, sCbxCompanyName, sCbxCompanyTitle,
    } = this.state;
    const {
      sCbxCompanyAddress, sCbxCompanyInoviceAddress, sCbxCompanyPhone1, sCbxCompanyPhone2,
    } = this.state;
    const {
      sCbxCompanyFax, sCbxCompanyEmail, sCbxHr, sCbxWorkPath, sCbxWorkCheckPath, sCbxTime, sCbxImpositionTime,
    } = this.state;
    const sCbxMaterialsUnitProps = { showConfig: sCbxMaterialsUnit, ...childProps };
    const sCbxCardboardUnitProps = { showConfig: sCbxCardboardUnit, ...childProps };
    const sCbxMachineUnitProps = { showConfig: sCbxMachineUnit, ...childProps };
    const dNetConversionRateProps = { showConfig: dNetConversionRate, ...childProps };
    const dNetMoneyProps = { showConfig: dNetMoney, ...childProps };
    const dNetPriceProps = { showConfig: dNetPrice, ...childProps };
    const iNetSquareMProps = { showConfig: iNetSquareM, ...childProps };
    const bCkxPercentileProps = { showConfig: bCkxPercentile, ...childProps };
    const sCbxDateTimeProps = { showConfig: sCbxDateTime, ...childProps };
    const sCbxLanguageProps = { showConfig: sCbxLanguage, ...childProps };
    const iCbxExitSystemProps = { showConfig: iCbxExitSystem, ...childProps };
    const sCbxNetIDProps = { showConfig: sCbxNetID, ...childProps };
    const sCbxNetVerifyCodeProps = { showConfig: sCbxNetVerifyCode, ...childProps };
    const sCbxHttpProps = { showConfig: sCbxHttp, ...childProps };
    const iNetMonthProps = { showConfig: iNetMonth, ...childProps };
    const sCbxServerFilePathProps = { showConfig: sCbxServerFilePath, ...childProps, dataList: sCbxServerFilePathData };
    const sCbxCompanyNameProps = { showConfig: sCbxCompanyName, ...childProps };
    const sCbxCompanyTitleProps = { showConfig: sCbxCompanyTitle, ...childProps };
    const sCbxCompanyAddressProps = { showConfig: sCbxCompanyAddress, ...childProps };
    const sCbxCompanyInoviceAddressProps = { showConfig: sCbxCompanyInoviceAddress, ...childProps };
    const sCbxCompanyPhone1Props = { showConfig: sCbxCompanyPhone1, ...childProps };
    const sCbxCompanyPhone2Props = { showConfig: sCbxCompanyPhone2, ...childProps };
    const sCbxCompanyFaxProps = { showConfig: sCbxCompanyFax, ...childProps };
    const sCbxCompanyEmailProps = { showConfig: sCbxCompanyEmail, ...childProps };
    const sCbxHrProps = { showConfig: sCbxHr, ...childProps, dataList: sCbxHrData };
    const sCbxWorkPathProps = { showConfig: sCbxWorkPath, ...childProps };
    const sCbxWorkCheckPathProps = { showConfig: sCbxWorkCheckPath, ...childProps };
    const sCbxTimeProps = { showConfig: sCbxTime, ...childProps };
    const sCbxImpositionTimeProps = { showConfig: sCbxImpositionTime, ...childProps };
    const formItemLayout = { labelCol: { span: 12 }, wrapperCol: { span: 12 } };
    return (
      <FormItem className={styles.searchSlaveForm}>
        <Row type="flex" justify="space-between">
          <Col span={11}>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="sCbxMaterialsUnit" useParentName showDefaultName="材料单位" {...sCbxMaterialsUnitProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCardboardUnit" useParentName showDefaultName="纸箱单位" {...sCbxCardboardUnitProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxMachineUnit" useParentName showDefaultName="上机规格计量单位" {...sCbxMachineUnitProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="dNetConversionRate" useParentName showDefaultName="转化率" {...dNetConversionRateProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="dNetMoney" useParentName showDefaultName="金额" {...dNetMoneyProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="dNetPrice" useParentName showDefaultName="价格" {...dNetPriceProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="iNetSquareM" useParentName showDefaultName="平方转米小数位" {...iNetSquareMProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="bCkxPercentile" useParentName showDefaultName="小数位(6)" {...bCkxPercentileProps} formItemLayout={formItemLayout} labelName="启用千分位显示" />
                </Col>
              </Row>
            </div>
            <div className={styles.tabChildDot}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="sCbxDateTime" useParentName showDefaultName="显示日期时间格式" {...sCbxDateTimeProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxLanguage" useParentName showDefaultName="默认语言" {...sCbxLanguageProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="iCbxExitSystem" useParentName showDefaultName="系统不操作退出(分钟)" {...iCbxExitSystemProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
            <div className={styles.tabChild}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="sCbxNetID" useParentName showDefaultName="外网ID" {...sCbxNetIDProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxNetVerifyCode" useParentName showDefaultName="接口验证码" {...sCbxNetVerifyCodeProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxHttp" useParentName showDefaultName="网络地址" {...sCbxHttpProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
          </Col>
          <Col span={11}>
            <div className={styles.tabChild}>
              <Row type="flex" justify="space-between">
                <Col span={11}>
                  <ShowType sName="iNetMonth" useParentName showDefaultName="数据默认显示月(个)" {...iNetMonthProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxServerFilePath" useParentName showDefaultName="服务器文件路径" {...sCbxServerFilePathProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyName" useParentName showDefaultName="公司名称" {...sCbxCompanyNameProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyTitle" useParentName showDefaultName="报表打印标题" {...sCbxCompanyTitleProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyAddress" useParentName showDefaultName="公司地址" textArea {...sCbxCompanyAddressProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyInoviceAddress" useParentName showDefaultName="开票地址" textArea {...sCbxCompanyInoviceAddressProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyPhone1" useParentName showDefaultName="电话1" {...sCbxCompanyPhone1Props} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyPhone2" useParentName showDefaultName="电话2" {...sCbxCompanyPhone2Props} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyFax" useParentName showDefaultName="传真" {...sCbxCompanyFaxProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxCompanyEmail" useParentName showDefaultName="电子邮件" {...sCbxCompanyEmailProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxHr" useParentName showDefaultName="人事专员" {...sCbxHrProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxWorkPath" useParentName showDefaultName="工单合版Json获取路径" {...sCbxWorkPathProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxWorkCheckPath" useParentName showDefaultName="工单合版check获取路径" {...sCbxWorkCheckPathProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxTime" useParentName showDefaultName="截稿时间点" {...sCbxTimeProps} formItemLayout={formItemLayout} />
                </Col>
                <Col span={11}>
                  <ShowType sName="sCbxImpositionTime" useParentName showDefaultName="拼版时间点" {...sCbxImpositionTimeProps} formItemLayout={formItemLayout} />
                </Col>
              </Row>
            </div>
          </Col>
        </Row>
      </FormItem>
    );
  }
}

export default TabSysParamComponent;
